﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;

/// <summary>
/// Summary description for DAL_VienPhi
/// </summary>
public class DAL_VienPhi : SqlConnectionRun
{
	public DAL_VienPhi()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public void ChuyenKhoa(string strVal, int idthu)
    {
        //string strVal=drkhamchuyenkhoa.SelectedValue;
        string[] s = strVal.Split(new char[] { '/' });     

        string sqlinsertso = " update vienphi..chitiet_vienphi set madv='" + s[0] + "',tendichvu=N'" + s[1] + "',makhoa='" + s[2] + "'" + " where ID='" + idthu.ToString() + "' ";
        sqlinsertso += " delete from phongkham..so_phieukham where MaThuDV='" + idthu.ToString() + "'";

        int result = SqlExecuteNoneQuery(sqlinsertso);      

        //Thinh khong hieu cho nay, 
        //////BS da cho kham them, sau do chuyen khoa luon
        string sSQL = "update vienphi..chitiet_vienphi set huy=1 where ID=(select top 1 ID from vienphi..chitiet_vienphi where maphieu=(select maphieu from vienphi..chitiet_vienphi where id=" + idthu.ToString() + ") and loai_kham_cp='khamthem' and makhoa='" + s[2] + "')";
        int result2 = SqlExecuteNoneQuery(sSQL);       
    }

    public DataTable LayThongTinDongChiTra(string MaBN, string MaDotKham)
    {
        string sql = @"select * from vienphi.dbo.tbdongchitrabn where mabn='" + MaBN + "' and madotkham ='" + MaDotKham + "' and datra is null";
        DataTable dt = SqlExecuteQueryReader(sql);
        return dt;
    }

    public void ThemDongChiTra(string MaBN, string Ngay, string MaDotKham)
    {
        string SQL = @"insert into Vienphi..tbdongchitraBN(mabn,ngay,madotkham)
                       values('"+ MaBN +"', '"+ Ngay +"','" + MaDotKham + "')";       
        SqlExecuteNoneQuery(SQL);
    }

    public void DanhDauDichVuDaKham(string mathudichvu)
    {       
        string strupdate = "Vienphi..DanhDauDichVuDaKham";
        List<SqlParameter> parameters = new List<SqlParameter>();
        parameters.Add(new SqlParameter("@ID", mathudichvu.Trim()));
        SqlRunStoredProcedureNoneQuery(strupdate, parameters);        
    }
}